<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2017/6/20
 * Time: 14:20
 */

namespace wodrow\site;

use config\ConfigLocal;

/**
 * Class App
 * @package wodrow\site
 *
 */
class App
{
    public $is_mobile = false;

    public function __construct()
    {
        $_local = ConfigLocal::getLocalConfog();
        require_once dirname(__DIR__)."/orm/phpar/ActiveRecord.php";
        \ActiveRecord\Config::initialize(function($cfg) use ($_local)
        {
            $cfg->set_model_directory(dirname(__DIR__)."/models");
            $cfg->set_connections(
                array(
                    'db' => "mysql://{$_local->db_user}:{$_local->db_password}@{$_local->db_host}/{$_local->db_name}?charset={$_local->db_charset}",
                )
            );
            $cfg->set_default_connection('db');
        });
    }

    public function run()
    {
//        date_default_timezone_set('PRC');
        if (substr($_SERVER['HTTP_HOST'], 0, 3) == 'api'){
            $this->is_mobile = true;
        }
        Site::$app = $this;
    }
}